package org.hhchat.leetcode.hashtable;

import java.util.HashMap;

/**
 * Created this one by HMH on 2017/10/3.
 */
public class code389_easy {

    static class Solution {
        public char findTheDifference(String s, String t) {
            HashMap<Character, Integer> map = new HashMap<>();
            for (char c : t.toCharArray()) {
                map.put(c,map.getOrDefault(c, 0) + 1);
            }

            for (char c : s.toCharArray()) {
                int count = map.get(c);
                if (count == 0) {
                    return c;
                }
                if (count == 1) {
                    map.remove(c);
                }else {
                    map.put(c, count-1);
                }
            }
            Character[] characters = map.keySet().toArray(new Character[0]);
            return characters[0];
        }
    }
    public static void main(String[] args){

    }
}
